#ifndef mylistener_h_
#define mylistener_h_
#include <uifcDefaultListeners.h>
#include <pfcGlobal.h>
#include "wxyOperation.h"
#include "logger.h"

enum MyButtonAction
{
    BTN_CLOSE,
    BTN_GET_LIST,
    BTN_START,
    BTN_nil
};
class MyPushButtonListener : public uifcDefaultPushButtonListener
{
private:
    MyButtonAction myaction;

public:
    MyPushButtonListener()
    {
        myaction = BTN_CLOSE;
    }
    MyPushButtonListener(MyButtonAction action)
    {
        myaction = action;
    }

public:
    void OnActivate(uifcPushButton_ptr handle)
    {
        switch (myaction)
        {
        case BTN_CLOSE:
            uifcExitDialog(handle->GetDialog(), 0);
            break;
        case BTN_GET_LIST:
            GetList(handle->GetDialog());
            break;
        case BTN_START:
            Export(handle->GetDialog());
            break;
        default:
            break;
        }
    }
};
class SelectDir : public uifcDefaultPushButtonListener
{
private:
    xstring name;
    bool flag; //是否更改工作目录

public:
    SelectDir(xstring component, bool changed = false)
    {
        name = component;
        flag = changed;
    }

public:
    void OnActivate(uifcPushButton_ptr handle)
    {
        pfcSession_ptr session = pfcGetProESession();
        pfcDirectorySelectionOptions_ptr options;
        options = pfcDirectorySelectionOptions::Create();
        try
        {
            xstring dir = session->UISelectDirectory(options);
            if (dir != xstring())
            {
                uifcInputPanel_ptr MyInputPanel = uifcInputPanelFind(handle->GetDialog(), name);
                MyInputPanel->SetTextValue(dir);
                if (flag)
                {
                    session->ChangeDirectory(dir);
                }
            }
        }
        OTK_EXCEPTION_PRINT_LOG
    }
};

class MyOptionMenuListener : public uifcDefaultOptionMenuListener
{
private:
    xstring pre_type;
    xstring cur_type;

public:
    //鼠标滑过选项时触发，获取更改前选项
    void OnItemHover(uifcOptionMenu_ptr handle)
    {
        pre_type = handle->GetTextValue();
    }
    void OnItemSelect(uifcOptionMenu_ptr handle)
    {
        //导出选项更改后，选项面板随之切换
        cur_type = handle->GetTextValue();
        xstring DialogName = handle->GetDialog();
        uifcDialog_ptr Dialog = uifcDialogFind(DialogName, DialogName);
        xstring LayoutName = "ly_op_" + pre_type;
        uifcLayout_ptr LayoutOption = uifcLayoutFind(DialogName, LayoutName);
        LayoutOption->SetVisible(xfalse);
        LayoutName = "ly_op_" + cur_type;
        LayoutOption = uifcLayoutFind(DialogName, LayoutName);
        LayoutOption->SetVisible(xtrue);
        GetList(handle->GetDialog());
    }
};

class MyListListener : public uifcDefaultListListener
{
public:
    void OnItemActivate(uifcList_ptr handle)
    {
        xstringsequence_ptr SelectedName = handle->GetSelectedItemNameArray();
        bool flag = true;
        for (int i = 0; i < SelectedName->getarraysize(); i++)
        {
            uifcListItem_ptr ListItem = uifcListItemFind(handle->GetDialog(),
                                                         handle->GetComponent(),
                                                         SelectedName->get(i));
            if (ListItem->GetCheckedState() == uifcCHECK_STATE_UNSET)
            {
                flag = false;
                break;
            }
        }
        for (int i = 0; i < SelectedName->getarraysize(); i++)
        {
            uifcListItem_ptr ListItem = uifcListItemFind(handle->GetDialog(),
                                                         handle->GetComponent(),
                                                         SelectedName->get(i));
            if (flag)
                ListItem->SetCheckedState(uifcCHECK_STATE_UNSET);
            else
                ListItem->SetCheckedState(uifcCHECK_STATE_SET);
        }
    }
};
class MyInputPanelListener : public uifcDefaultInputPanelListener
{
public:
    void OnChange(uifcInputPanel_ptr handle)
    {
        xstring dir = handle->GetTextValue();
        pfcSession_ptr session = pfcGetProESession();
        try
        {
            session->ChangeDirectory(dir);
        }
        OTK_EXCEPTION_PRINT_LOG
    }
    void OnKeyDown(uifcInputPanel_ptr handle) { LOG(LOG_INFO) << "Change Directory"; }
    void OnFocusOut(uifcInputPanel_ptr handle) { LOG(LOG_INFO) << "Change Directory"; }
    void OnFocusIn(uifcInputPanel_ptr handle) { LOG(LOG_INFO) << "Change Directory"; }
    void OnActivate(uifcInputPanel_ptr handle) { LOG(LOG_INFO) << "Change Directory"; }
    void OnDrop(uifcInputPanel_ptr handle) { LOG(LOG_INFO) << "Change Directory"; }
    void OnDragExit(uifcInputPanel_ptr handle) { LOG(LOG_INFO) << "Change Directory"; }
    void OnDragMove(uifcInputPanel_ptr handle) { LOG(LOG_INFO) << "Change Directory"; }
    void OnHelp(uifcInputPanel_ptr handle) { LOG(LOG_INFO) << "Change Directory"; }
    void OnDragEnter(uifcInputPanel_ptr handle) { LOG(LOG_INFO) << "Change Directory"; }
};
#endif